﻿using AutoMapper;

namespace D.WebApi.Core.AutoMapperUtils
{
    /// <summary>
    /// AutoMapper的全局实体映射配置静态类
    /// </summary>
    public class AutoMapperConfiguration
    {
        private IMapper Mapper;
        public AutoMapperConfiguration(Dictionary<Type, Type> t)
        {
            Mapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MappingProfile(t));
            }).CreateMapper();
        }

        public T Map<T>(object source) where T : class
        {
            return Mapper.Map<T>(source);
        }
    }
}
